import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SettlementRecordApi } from '#/api/spa/settlement';

import { z } from '#/adapter/form';
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
import { DICT_SPA_TYPE } from '#/utils/dictSpa';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'groupId',
      label: '集团ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入集团ID',
      },
    },
    {
      fieldName: 'storeId',
      label: '门店ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入门店ID',
      },
    },
    {
      fieldName: 'settlementCode',
      label: '结算编码',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入结算编码',
      },
    },
    {
      fieldName: 'settlementType',
      label: '结算类型',
      rules: 'required',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Type, 'string'),
        placeholder:
          '请选择结算类型：consumption-消费结算，recharge-充值，refund-退款，adjustment-调整',
      },
    },
    {
      fieldName: 'accountId',
      label: '结算账户ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入结算账户ID',
      },
    },
    {
      fieldName: 'customerId',
      label: '客户ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入客户ID',
      },
    },
    {
      fieldName: 'consumptionIds',
      label: '关联的消费登记ID列表',
      component: 'Input',
      componentProps: {
        placeholder: '请输入关联的消费登记ID列表',
      },
    },
    {
      fieldName: 'consumptionCount',
      label: '消费项目数量',
      component: 'Input',
      componentProps: {
        placeholder: '请输入消费项目数量',
      },
    },
    {
      fieldName: 'totalAmount',
      label: '总金额',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入总金额',
      },
    },
    {
      fieldName: 'discountAmount',
      label: '优惠金额',
      component: 'Input',
      componentProps: {
        placeholder: '请输入优惠金额',
      },
    },
    {
      fieldName: 'actualAmount',
      label: '实付金额',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入实付金额',
      },
    },
    {
      fieldName: 'paymentMethod',
      label: '支付方式',
      component: 'Input',
      componentProps: {
        placeholder:
          '请输入支付方式：cash-现金，card-银行卡，wechat-微信，alipay-支付宝，balance-余额',
      },
    },
    {
      fieldName: 'paymentStatus',
      label: '支付状态',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(
          DICT_SPA_TYPE.SPA_Settlement_Payment_Status,
          'string',
        ),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'paymentTime',
      label: '支付时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'transactionId',
      label: '第三方交易流水号',
      component: 'Input',
      componentProps: {
        placeholder: '请输入第三方交易流水号',
      },
    },
    {
      fieldName: 'settlementStatus',
      label: '结算状态',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'settlementTime',
      label: '结算时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'groupId',
      label: '集团ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入集团ID',
      },
    },
    {
      fieldName: 'storeId',
      label: '门店ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入门店ID',
      },
    },
    {
      fieldName: 'settlementCode',
      label: '结算编码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入结算编码',
      },
    },
    {
      fieldName: 'settlementType',
      label: '结算类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Type, 'string'),
        placeholder:
          '请选择结算类型：consumption-消费结算，recharge-充值，refund-退款，adjustment-调整',
      },
    },
    {
      fieldName: 'accountId',
      label: '结算账户ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入结算账户ID',
      },
    },
    {
      fieldName: 'customerId',
      label: '客户ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入客户ID',
      },
    },
    {
      fieldName: 'consumptionIds',
      label: '消费登记ID列表',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入关联的消费登记ID列表',
      },
    },

    {
      fieldName: 'paymentMethod',
      label: '支付方式',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(
          DICT_SPA_TYPE.SPA_Settlement_Payment_Method,
          'string',
        ),
        placeholder:
          '请选择支付状态：pending-待支付，paid-已支付，failed-支付失败',
      },
    },
    {
      fieldName: 'paymentStatus',
      label: '支付状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(
          DICT_SPA_TYPE.SPA_Settlement_Payment_Status,
          'string',
        ),
        placeholder:
          '请选择支付状态：pending-待支付，paid-已支付，failed-支付失败',
      },
    },
    {
      fieldName: 'paymentTime',
      label: '支付时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'transactionId',
      label: '第三方交易流水号',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入第三方交易流水号',
      },
    },
    {
      fieldName: 'settlementStatus',
      label: '结算状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder:
          '请选择结算状态：pending-待结算，completed-已完成，cancelled-已取消',
      },
    },
    {
      fieldName: 'settlementTime',
      label: '结算时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<SettlementRecordApi.SettlementRecord>['columns'] {
  return [
    {
      field: 'id',
      title: '主键ID',
      minWidth: 120,
    },
    // {
    //   field: 'groupId',
    //   title: '集团ID',
    //   minWidth: 120,
    // },
    // {
    //   field: 'storeId',
    //   title: '门店ID',
    //   minWidth: 120,
    // },
    {
      field: 'settlementCode',
      title: '结算编码',
      minWidth: 120,
    },
    {
      field: 'settlementType',
      title: '结算类型',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.SPA_Settlement_Type.toUpperCase() },
      },
    },
    {
      field: 'accountId',
      title: '结算账户ID',
      minWidth: 120,
    },
    {
      field: 'customerId',
      title: '客户ID',
      minWidth: 120,
    },
    {
      field: 'consumptionIds',
      title: '消费登记ID列表',
      minWidth: 120,
    },
    {
      field: 'consumptionCount',
      title: '消费项目数量',
      minWidth: 120,
    },
    {
      field: 'totalAmount',
      title: '总金额',
      minWidth: 120,
    },
    {
      field: 'discountAmount',
      title: '优惠金额',
      minWidth: 120,
    },
    {
      field: 'actualAmount',
      title: '实付金额',
      minWidth: 120,
    },
    {
      field: 'paymentMethod',
      title: '支付方式',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: {
          type: DICT_SPA_TYPE.SPA_Settlement_Payment_Method.toUpperCase(),
        },
      },
    },
    {
      field: 'paymentStatus',
      title: '支付状态',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: {
          type: DICT_SPA_TYPE.SPA_Settlement_Payment_Status.toUpperCase(),
        },
      },
    },
    {
      field: 'paymentTime',
      title: '支付时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'transactionId',
      title: '第三方交易流水号',
      minWidth: 120,
      // cellRender: {
      //   name: 'CellDict',
      //   props: { type: DICT_SPA_TYPE.HandCardStatus },
      // },
    },
    {
      field: 'settlementStatus',
      title: '结算状态',
      minWidth: 120,
    },
    {
      field: 'settlementTime',
      title: '结算时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
